﻿################################################################################
## @brief
#       email     stanleyguo0207@163.com
#       github    https://github.com/stanleyguo0207
#       gitee     https://gitee.com/stanleyguo0207
#       for protobuf3
#
################################################################################

message(STATUS "Enter FindProtobuf.cmake")

find_package (Protobuf
  CONFIG
  HINTS "D:/protobuf/cmake"
  REQUIRED
  )

if (Protobuf_FOUND OR PROTOBUF_FOUND)
  if (TARGET protobuf::libprotobuf)
    message (STATUS "TARGET protobuf::libprotobuf found")
    set (_asfinger_PROTOBUF_LIBRARIES protobuf::libprotobuf)
  else ()
    message (WARNING "TARGET protobuf::libprotobuf not found")
    set (_asfinger_PROTOBUF_LIBRARIES ${PROTOBUF_LIBRARIES})
  endif ()

  if (TARGET protobuf::libprotoc)
    message (STATUS "TARGET protobuf::libprotoc found")
    set (_asfinger_PROTOBUF_PROTOC_LIBRARIES protobuf::libprotoc)
    get_target_property (_asfinger_PROTOBUF_WELLKNOWN_INCLUDE_DIR protobuf::libprotoc INTERFACE_INCLUDE_DIRECTORIES)
  else ()
    message (WARNING "TARGET protobuf::libprotoc not found")
    set (_asfinger_PROTOBUF_PROTOC_LIBRARIES ${PROTOBUF_PROTOC_LIBRARIES})
    set (_asfinger_PROTOBUF_WELLKNOWN_INCLUDE_DIR ${PROTOBUF_INCLUDE_DIRS})
  endif ()

  if (TARGET protobuf::protoc)
    message (STATUS "TARGET protobuf::protoc found")
    set (_asfinger_PROTOBUF_PROTOC protobuf::protoc)
    set (_asfinger_PROTOBUF_EXECUTABLE $<TARGET_FILE:protobuf::protoc>)
  else ()
    message (WARNING "TARGET protobuf::protoc not found")
    set (_asfinger_PROTOBUF_PROTOC ${Protobuf_PROTOC_LIBRARY})
    set (_asfinger_PROTOBUF_EXECUTABLE ${Protobuf_PROTOC_EXECUTABLE})
  endif ()

  set (_asfinger_PROTOBUF_INCLUDE_DIR ${_asfinger_PROTOBUF_WELLKNOWN_INCLUDE_DIR})
  set (_asfinger_FIND_PROTOBUF "if(NOT Protobuf_FOUND AND NOT PROTOBUF_FOUND)\n find_package(Protobuf)\n endif()")
endif ()

message (STATUS "_asfinger_PROTOBUF_PROTOC: ${_asfinger_PROTOBUF_PROTOC}")
message (STATUS "_asfinger_PROTOBUF_EXECUTABLE: ${_asfinger_PROTOBUF_EXECUTABLE}")
message (STATUS "_asfinger_PROTOBUF_PROTOC_LIBRARIES: ${_asfinger_PROTOBUF_PROTOC_LIBRARIES}")
message (STATUS "_asfinger_PROTOBUF_INCLUDE_DIR: ${_asfinger_PROTOBUF_INCLUDE_DIR}")
message (STATUS "_asfinger_PROTOBUF_LIBRARIES: ${_asfinger_PROTOBUF_LIBRARIES}")

message(STATUS "Leave FindProtobuf.cmake")